package lab03.Test03;

import javax.swing.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by Administrator on 2017/11/16.
 */
public class Test {
    public static void main(String[] args) throws FileNotFoundException {
        String path = "D:\\test.txt";
        FileOutputStream fileOutputStream = null;
        //字节流写文件
        try {
            fileOutputStream = new FileOutputStream(path);
            //转换字节数组
            fileOutputStream.write("Beijing欢迎你！".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
//字节流读文件
        FileInputStream fileInputStream = new FileInputStream(path);
        int tmp;
        try {
            while ((tmp = fileInputStream.read()) != -1) {
                System.out.println((char) tmp);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }}
